package com.xxx.shetuan3.dao;

import com.xxx.shetuan3.pojo.StudentAndOrganization;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface StudentAndOrganizationDao {
    @Insert("insert into student_and_organization " +
            "(student_id,organization_id,state) " +
            "values (#{studentId},#{organizationId},#{state})")
    public int saveStudentAndOrganization(StudentAndOrganization studentAndOrganization);

    @Select("select id Id,student_id studentId,organization_id organizationId,state " +
            "from student_and_organization " +
            "where id = #{studentAndOrganizationId}")
    public StudentAndOrganization findStudentAndOrganizationByStudentAndOrganizationId(Integer studentAndOrganizationId);

    @Update("update student_and_organization " +
            "set state = #{state} " +
            "where id = #{Id}")
    public int updateStudentAndOrganizationStateByStudentAndOrganizationId(String state, Integer Id);

    @Delete("delete from student_and_organization " +
            "where id = #{id}")
    public int deleteStudentAndOrganizationById(Integer studentAndOrganizationId);

    @Select("select id Id,student_id studentId,organization_id organizationId,state " +
            "from student_and_organization " +
            "where organization_id = #{organizationId} and state = #{state}")
    public List<StudentAndOrganization> findStudentAndOrganizationByStateAndOrganizationId(String state,Integer organizationId);

    @Select("select id Id,student_id studentId,organization_id organizationId,state " +
            "from student_and_organization " +
            "where student_id = #{studentId} and state=#{state} ")
    public List<StudentAndOrganization> findStudentAndOrganizationByStateAndStudentId(String state, Integer studentId);

    @Select("select id Id,student_id studentId,organization_id organizationId,state " +
            "from student_and_organization " +
            "where student_id = #{studentId} and organization_id = #{organizationId}")
    public StudentAndOrganization findStudentAndOrganizationByStudentIdAndOrganizationId(Integer studentId,Integer organizationId);

}
